/**
 * Copyright (c) 2008, Mu Dynamics.
 *  All rights reserved.
 *  
 *   Redistribution and use in source and binary forms, with or without modification, 
 *   are permitted provided that the following conditions are met:
 *   
 *  - Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice, 
 *     this list of conditions and the following disclaimer in the documentation and/or 
 *     other materials provided with the distribution.
 *  - Neither the name of the "Mu Dynamics" nor the names of its contributors may be used 
 *     to endorse  or promote products derived from this software without specific prior 
 *     written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.mu.jacob.core.generator;

import java.util.ArrayList;
import java.util.List;

import org.apache.tools.ant.BuildException;

import com.google.inject.Injector;
import com.google.inject.Singleton;

/**
 * Default Jacob config implementation.
 * DefaultConfig is a singleton inside the application
 * and passed to components using Guice DI.
 * @author Adam Smyczek
 */
@Singleton
public class DefaultConfig implements Config {
	
	/* Guice injector */
	private Injector injector = null;
	
	/* List of model sets */
	private List<ModelSet> modelSets = new ArrayList<ModelSet>();
	
	/* class path string */
	private String classPath = "";
	
	/**
	 * Protected constructor, do not directly instantiate it.
	 * Use injector.getInstance(Config.class) instead.
	 */
	protected DefaultConfig() {
		super();
	}

	/**
	 * Initialize with injector after instantiation
	 * @param injector
	 */
	public void initialize(Injector injector) {
		this.injector = injector;
	}
	
	/**
	 * Delegate to Guice injector
	 */
	public <T> T getInstance(Class<T> clazz) {
		if (injector == null) {
			throw new BuildException("Configuration is not initialized!");
		}
		return injector.getInstance(clazz);
	}
	
	/**
	 * Add new model set
	 * @param modelSet
	 */
	public void addModelSet(ModelSet modelSet) {
		modelSets.add(modelSet);
	}

	/**
	 * Add all for model sets
	 * @param modelSets
	 */
	public void addModelSets(List<ModelSet> modelSets) {
		this.modelSets.addAll(modelSets);
	}
	
	/**
	 * @return model sets list
	 */
	public List<ModelSet> getModelSets() {
		return modelSets;
	}
	
	/**
	 * Class path list as string
	 */
	public String getClassPath() {
		return classPath;
	}

	/**
	 * Initialize class path
	 * @param classPath the classPath to set
	 */
	public void setClassPath(String classPath) {
		this.classPath = classPath;
	}

}
